﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using LeHouse.Server.Dto;
using LeHouse.Server.Service;
namespace LeHouse.Server.WebApi.Controllers
{
    public class StaffController : ApiController
    {
        /// <summary>
        /// 员工信息的下拉框的获取
        /// </summary>
        /// <param name="Dmenuid">枚举编号</param>
        /// <returns>符合要求的下拉框数据</returns>
        [HttpGet]
        [Route("api/Staff/GetHouseType")]
        public IEnumerable<System_Staff> GetHouseType([FromUri]int Dmenuid)
        {
            //字典表的实例化
            System_StaffService dic = new System_StaffService();
            List<System_Staff> droplist = dic.Select(p => p.T_Departmentid == Dmenuid);
            return droplist;
        }

        /// <summary>
        /// 员工信息的数据添加
        /// </summary>
        /// <param name="s">ajax传过来的需要添加的数据</param>
        /// <returns></returns>       
        [HttpPost]
        [Route("api/Staff/Postinsert")]
        public bool Insert([FromBody] System_Staff parms)
        {
            parms.T_Date = DateTime.Now;
            parms.T_State = "1";
            System_StaffService insert = new System_StaffService();
            if (insert.Insert(parms) == true)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">员工的编号</param>
        /// <returns>false/true</returns>
        [HttpPost]
        [Route("api/Staff/Delete")]
        public bool Delete([FromBody] int id)
        {
            System_StaffService delete = new System_StaffService();
            if (delete.DeleteById(id) == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 根据员工编号获取员工的信息
        /// </summary>
        /// <param name="?">员工的编号</param>
        /// <returns>false/true判断是否为空</returns>
        [HttpPost]
        [Route("api/Staff/UpdateByid")]
        public dynamic UpdateBYid([FromBody]int id)
        {
            System_StaffService updatebyid = new System_StaffService();
            var d1 = updatebyid.SelectById(id);
            return d1;
        }

        /// <summary>
        /// 修改员工信息
        /// </summary>
        /// <param name="sta">获取修改的员工信息</param>
        /// <returns>false/true</returns>
        [HttpPost]
        [Route("api/Staff/Update")]
        public bool Update([FromBody] System_Staff sta)
        {
            System_StaffService update = new System_StaffService();
            if (update.Update(sta) == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 修改员工状态
        /// </summary>
        /// <param name="sta"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Staff/UpdateState")]
        public bool UpdateState(System_Staff obj)
        {
            System_StaffService update = new System_StaffService();
            var d1 = update.SelectById(Convert.ToInt32(obj.T_StaffID));
            d1.T_State = obj.T_State;
            if (update.Update(d1) == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 根据条件获取员工信息集
        /// </summary>
        /// <param name="S_name"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Staff/select")]
        public dynamic select([FromBody]string S_name)
        {
            System_StaffService staff = new System_StaffService();

            if (string.IsNullOrEmpty(S_name))
            {
                return staff.Select();
            }

            var d1 = staff.Select().Where(p => p.T_Name.Contains(S_name)).ToList();
            return d1;
        }



    }
}
